#!/usr/bin/env python
# -*- coding: UTF-8 -*-

from oriolus.pith.packets.version import Version
from oriolus.pith.packets.packet import FullName
from oriolus.trotter.trotter import Trotter

class LatestStrategy:
    def select_packets(self, full_name_list):
        dictionary = {}
        ordered_names = []

        for full_name in full_name_list:
            if full_name.name in dictionary:
                current_max_version = dictionary[full_name.name].version
                if Version(full_name.version) > Version(current_max_version):
                    dictionary[full_name.name] = full_name
            else:
                dictionary[full_name.name] = full_name
                ordered_names.append(full_name.name)

        return [dictionary[name] for name in ordered_names]